using UnityEngine;
using System.Collections;

public class KinectController : MonoBehaviour {

	public KUInterface kinectInterface;
	public GameObject backgroundPlane;

	float lastCameraAngle = 0f;

	// Use this for initialization
	void Start () {
		kinectInterface = GameObject.FindObjectOfType(typeof(KUInterface)) as KUInterface;
		
		if (backgroundPlane != null)
			kinectInterface.useRGB = true;
	}
	
	// Update is called once per frame
	void Update () {
		if (backgroundPlane != null)
			backgroundPlane.renderer.material.SetTexture("_MainTex", kinectInterface.GetTextureImage());


		float kinectAngle = kinectInterface.GetCameraAngle();
		if (!Mathf.Approximately(kinectAngle, lastCameraAngle))
		{
			Camera.main.transform.Rotate(new Vector3(lastCameraAngle - kinectAngle, 0, 0));
			lastCameraAngle = kinectAngle;
		}
	}

}
